#include <cblas.h> // 对于BLAS
#include <lapacke.h> // 对于LAPACK
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <cmath> 
#include <vector>
#include "Sphere.hpp"
#include "Spline.hpp"

std::string directory = "src/build/";  // 目标目录

double pi = M_PI;

double F(double x)
{
    return 1/(1+x*x);
}

template <typename T>

double polynomial(double x, T p) {
    return p.SplineReturn(x);  
}

int main()
{
    std::vector<double> vec;
    std::vector<double> y1;
    for(int i = 0; i<=10;i++){
            vec.push_back(-5 + 10*(double)i/10);
            y1.push_back(F(-5 + 10*(double)i/10));
        }
    double fa=10/std::pow(26,2);
    double fb=-10/std::pow(26,2);
    PPFormSpline p1(vec,y1,"complete",fa,fb);
    BSpline p2(vec,y1,3,"complete",fa,fb);
    std::ofstream file1(directory + "data_test1" + ".csv");
        if (!file1.is_open()) {
            std::cerr << "Failed to open file" << std::endl;
            return 1;
        }

        for (double x = -5; x <= 5; x += 0.1) {
            double y = polynomial<PPFormSpline>(x,p1);
            file1 << x << "," << y << std::endl;
        }

    std::ofstream file2(directory + "data_test2" + ".csv");
        if (!file2.is_open()) {
            std::cerr << "Failed to open file" << std::endl;
            return 1;
        }

        for (double x = -5; x <= 5; x += 0.1) {
            double y = polynomial<BSpline>(x,p2);
            file2 << x << "," << y << std::endl;
        }


        file2.close();
    return 0; 
}